package com.twotiger.and.activity.user;

import java.util.HashMap;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import app.twotiger.p2p.R;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.twotiger.and.Constants;
import com.twotiger.and.activity.HomeActivity;
import com.twotiger.and.activity.WebViewPage;
import com.twotiger.and.activity.base.BaseActivity;
import com.twotiger.and.activity.base.BaseHandler;
import com.twotiger.and.bean.Basebean;
import com.twotiger.and.bean.BroswerUrl;
import com.twotiger.and.util.ViewUtils;

public class RegistSuccesActivity extends BaseActivity {

    private static final int OPENPAYMENTSUCCES = 0;
    private static final int OPENPAYMENTFAIL = 1;
    private HashMap<String, String> parms;
    private TextView sub_title_center_tv;

    @Override
    protected void processLogic() {
        sub_title_center_tv.setText("成功");
        parms = getParm();

    }

    @Override
    protected void setListener() {
        handler = new BaseHandler(this) {
            @Override
            public void handleMessage(Message msg) {
                switch (msg.what) {
                case OPENPAYMENTSUCCES:
                    Basebean result_open = JSONObject.parseObject((String) msg.obj, Basebean.class);
                    if (result_open.isOk()) {
                        BroswerUrl responseinfo = JSON.parseObject(result_open.data, BroswerUrl.class);
                        Intent intent = new Intent(getContext(), WebViewPage.class);
                        intent.putExtra("title", "汇付天下托管账号");
                        intent.putExtra("url", responseinfo.getUrl());
                        intent.putExtra("BUSINESS_TYPE", WebViewPage.TYPE_PAYMENT_REGIST);
                        startActivity(intent);
                        finish();
                    }
                    break;
                case OPENPAYMENTFAIL:
                    showToast("网络异常");
                    break;
                default:
                    break;
                }
                super.handleMessage(msg);
            }
        };
    }

    @Override
    protected void findViewById(View view) {
        view.findViewById(R.id.open_proxy_count_btn).setOnClickListener(this);
        view.findViewById(R.id.to_home_btn).setOnClickListener(this);
        sub_title_center_tv = (TextView) view.findViewById(R.id.sub_title_center_tv);
    }

    @SuppressLint("InflateParams")
    @Override
    protected View loadViewLayout(LayoutInflater inflater) {
        View view = inflater.inflate(R.layout.activity_regist_succes, null);
        return view;
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
        case R.id.to_home_btn:
            startNewActivity(new Intent(this, HomeActivity.class), R.anim.push_left_in, R.anim.push_left_out, true);
            break;
        case R.id.open_proxy_count_btn:
            if (ViewUtils.isFastDoubleClick(view)) {
                return;
            }
            openpayment();
            break;
        default:
            break;
        }

    }

    private void openpayment() {
        parms.clear();
        parms.put("token", getToken());
        getDate(parms, Constants.REGISTHF, handler, OPENPAYMENTSUCCES, OPENPAYMENTFAIL, true, false, false);
    }

    @Override
    protected void onBackPress() {

    }

}
